package com.palazzisoft.balonpie.controller;

import java.io.IOException;

import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.DefaultHttpClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class MainController {
    
    @RequestMapping(value = "/main.htm")
    public String mainPage() throws ClientProtocolException, IOException, AuthenticationException {    	
    	HttpClient httpClient = new DefaultHttpClient();
    	
    	HttpGet httpGet = new HttpGet("http://localhost:8080/pende/estelares.htm");
    	
        UsernamePasswordCredentials creds = new UsernamePasswordCredentials("pablo", "1234");
        httpGet.addHeader(new BasicScheme().authenticate(creds, httpGet));
    	
    	HttpResponse httpResponse = httpClient.execute(httpGet);
        return "/main/main";
    }
    
    @RequestMapping(value = "/createTournament.htm")
    public String createTournament() {
    	return "/tournament/tournament";
    }
    
    @RequestMapping(value = "/error.htm")
    public String showErrorPage() {
    	return "/error";
    }
    
    @RequestMapping(value = "/admin.htm")    
    public String justAdmins() {       
    	return "/admin/index";
    }
}
